//
//  UIColor+CL.m
//  IntegralMall
//
//  Created by 朱跃龙 on 2017/9/26.
//  Copyright © 2017年 朱跃龙. All rights reserved.
//

#import "UIColor+CL.h"

#define random(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]

#define randomColor random(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))

@implementation UIColor (CL)

+ (UIColor *)green{
    
    UIColor *color = [UIColor colorWithRed:8/255.0 green:188/255.0 blue:5/255.0 alpha:1];
    
    return color;
    
}

+ (UIColor *)red{
    
    UIColor *color = [UIColor colorWithRed:219/255.0 green:33/255.0 blue:39/255.0 alpha:1];
    
    return color;
    
}

+ (UIColor *)gray{
    
    UIColor *color = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1];
    
    return color;
    
}

+ (UIColor *)bule{
    
    UIColor *color = [UIColor colorWithRed:26/255.0 green:131/255.0 blue:213/255.0 alpha:1];
    
    return color;
    
}

+ (UIColor *)grayclear{
    
    UIColor *color =[UIColor colorWithRed:204/255.0 green:204/255.0 blue:204/255.0 alpha:1];
    
    return color;
    
}

+ (UIColor *)white{
    
    UIColor *color =[UIColor colorWithRed:249/255.0 green:249/255.0 blue:249/255.0 alpha:1];
    
    return color;
    
}

+ (UIColor *)colorWithHexString: (NSString *)color
{
    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    // String should be 6 or 8 characters
    if ([cString length] < 6) {
        return [UIColor clearColor];
    }
    // 判断前缀
    if ([cString hasPrefix:@"0X"])
        cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"])
        cString = [cString substringFromIndex:1];
    if ([cString length] != 6)
        return [UIColor clearColor];
    // 从六位数值中找到RGB对应的位数并转换
    NSRange range;
    range.location = 0;
    range.length = 2;
    //R、G、B
    NSString *rString = [cString substringWithRange:range];
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];
}

//生成随机色
+ (UIColor *)setrandomColor
{
    
    UIColor *color = randomColor;
    
    return color;
}


@end
